<%--
  Created by IntelliJ IDEA.
  User: 86150
  Date: 2022/10/24
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui-v2.7.6/layui/css/layui.css" >
    <script src="${pageContext.request.contextPath}/static/layui-v2.7.6/layui/layui.js"></script>
</head>
<body>
<form class="layui-form" action="" >
    <div class="layui-form-item pass" >
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password"  lay-verify="required" placeholder="请输入旧密码" autocomplete="off"
                   class="layui-input" id="lonpass1">
        </div>
    </div>
    <div class="layui-form-item pass" >
        <label class="layui-form-label">用户新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password"  lay-verify="required" placeholder="请输入新密码" autocomplete="off"
                   class="layui-input" id="pass1">
        </div>
    </div>
    <div class="layui-form-item pass" >
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password"  lay-verify="required|pass" placeholder="请再次输入新密码"
                   autocomplete="off" class="layui-input" id="pass2">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formSaveUser">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['table','layer','form','jquery'], function() {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload
            , element = layui.element;
        var namestatus = true;
        // 自定义校验  验证两次密码是不是一样
        form.verify({
            pass: function (value) { //自定义lay-verify的昵称，value：表单的值
                var pass1 = $("#pass1").val();
                if (value != pass1) {
                    return "两次密码不一致！！！";
                }

            }
        });
        //提交表单
        // Layui提交表单 监听提交  data代表的是form表单里面的所有的内容
        form.on('submit(formSaveUser)', function(data){
            if(namestatus){
                $.ajax({
                    url:"${pageContext.request.contextPath}",
                    type:"post",
                    dataType:"JSON",
                    data:data.field,//表单里所有数据
                    success:function (ret){
                        alert(ret.data)
                        if (ret.data == true){
                            //关闭所有弹框
                            layer.closeAll();
                            //刷新页面
                            table.reload('test');
                        }
                    }
                })
            }
            return false;
        });

    });
</script>
</body>
</html>
